export default {
  methods: {
	getAppPosition() {
		uni.getLocation({
			type: 'gcj02',
			geocode: true,
			success: function(res) {
				console.log('**定位信息', res);
				uni.setStorageSync('location',res)
			},
			fail: function(err) {

			}
		});
		uni.setStorageSync('location',res)
	},
    toUrl(page,isAuth) {
		if(isAuth){
			let userInfo = uni.getStorageSync('userInfo') || {}
			console.log('userInfo',userInfo)
			if (!userInfo.id) {
				uni.showModal({
					title: '提示',
					content: '是否前往登录?',
					success: (res) => {
						if (res.confirm) {
							this.toUrl('/pages/login/login')
						}
					}
				})
				return
			}
		}
		uni.navigateTo({
			url:page
		})
    },
	formatDate(timestamp,formatType){
		const date = new Date(timestamp * 1000);
		const year = date.getFullYear();
		const month = ("0" + (date.getMonth() + 1)).slice(-2);
		const day = ("0" + date.getDate()).slice(-2);

		let formattedDate = '';

		switch (formatType) {
			case 'YYYY年MM月DD日':
			  formattedDate = `${year}年${month}月${day}日`;
			  break;
			case 'MM/DD/YYYY':
			  formattedDate = `${month}/${day}/${year}`;
			  break;
			default:
			  formattedDate = `${year}-${month}-${day}`;
		}

		return formattedDate;
	},
    // 配置当前页面分享
    onShareAppMessage() {
      return {
        title: '西安善佑家政',
        path: getCurrentPages()[getCurrentPages().length - 1].route,
      }
    },
    // 配置分享到朋友圈
    onShareTimeline() {
      return {
        title: '西安善佑家政',
        query: '',
      }
    }
  },
}
